<template>
  <div>
    <a-row :gutter="20">
      <a-col :xl="4" :xs="24">
        <a-card :bordered="false">
          <unit-tree @changeSelect="unitTreeChangeSelect"></unit-tree>
        </a-card>
      </a-col>
      <a-col :xl="20" :xs="24">
        <user-list ref="userList" :unit-id="currentUnitId"></user-list>
      </a-col>
    </a-row>
  </div>
</template>
<script>
import UnitTree from "@/views/org/user/component/unitTree"; //部门树
import UserList from "@/views/org/user/component/userList"; //用户列表
import { userFormUrl } from "@/api/org/user";
export default {
  name: "OrgUserList",
  components: { UnitTree, UserList },
  data() {
    return {
      currentUnitId: undefined,
    };
  },
  methods: {
    reloadTable() {
      this.$refs["userList"].reload();
    },
    unitTreeChangeSelect(selectKey, selectData) {
      if (this.currentUnitId) {
        this.currentUnitId = selectKey;
        this.reloadTable();
        return;
      }
      this.currentUnitId = selectKey;
    },
  },
  beforeRouteLeave(to, from, next) {
    if (to.path.indexOf(userFormUrl) > -1) {
      from.meta.keepAlive = true;
    } else {
      from.meta.keepAlive = false;
    }
    next();
  },
};
</script>
